import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QDesktopWidget, QAction
import Ui_develop_help
import  help_modules.config_help as config_help_process
import  help_modules.re_help as re_help_process

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.ui = Ui_develop_help.Ui_DevelopHelp()
        self.ui.setupUi(self)
        self.menu_bar = self.ui.menubar
        self.operator_menu = self.menu_bar.addMenu("操作")

        self.init_ui()

    def show_msg(self, msg):
        """显示结果"""
        self.ui.textEdit_out.setPlainText(msg)

    def get_input(self):
        """获取用户输入"""
        _t = self.ui.textEdit_in.toPlainText()
        return _t
        
    def init_menu_bar(self):
        """初始化功能菜单"""
        show_all_help = QAction("使用帮助", self)
        show_all_help.triggered.connect(self.show_all_help_msg)
        self.operator_menu.addAction(show_all_help)
        
        config_help = QAction("系统参数生成", self)
        config_help.triggered.connect(self.do_config_help)
        self.operator_menu.addAction(config_help)
        
        re_help = QAction("正则表达式", self)
        re_help.triggered.connect(self.do_re_help)
        self.operator_menu.addAction(re_help)
    
    def show_all_help_msg(self):
        """显示所有的帮助文档"""
        _s = []
        _s.append(config_help_process.help_txt())
        _s.append("--------------------------------\n")
        _s.append(re_help_process.help_txt())
        _s.append("--------------------------------\n")
        
        self.show_msg("".join(_s))
        
    def do_re_help(self):
        """执行正则处理"""
        _user_input = self.get_input()
        txt = re_help_process.process_txt(_user_input)
        self.show_msg(txt)        
    
    def do_config_help(self):
        """生成配置功能的重复代码"""
        _user_input = self.get_input()
        txt = config_help_process.process_txt(_user_input)
        self.show_msg(txt)

    def init_ui(self):
        # 设定初始的demo参数
        self.init_menu_bar()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    form = MainWindow()
    form.show()

    sys.exit(app.exec_())
